package scheduler

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commEntityManager"
	"gitee.com/fierce_wolf/go-fox-edge-common/commRedisRpc"
	"go-fox-edge-persist/entityUpdater"
	"time"
)

type RedisListValueScheduler struct {
}

// Scheduler 创建一个线程
func (e *RedisListValueScheduler) Scheduler() {
	go e.scheduler()
}

// 线程函数
func (e *RedisListValueScheduler) scheduler() {
	for true {
		if !commEntityManager.EntityManager.Initialized {
			time.Sleep(1 * time.Second)
			continue
		}

		requestVO, err := commRedisRpc.Persist.Server.ValueRequest.Pop(1 * time.Second)
		if err != nil || requestVO == nil {
			continue
		}

		// 处理数据
		e.updateDeviceRespond(requestVO)
	}
}

func (e *RedisListValueScheduler) updateDeviceRespond(requestVO *commRedisRpc.TaskRespondVO) {
	for _, operateRespondVO := range requestVO.RespondVOS {
		err := entityUpdater.EntityUpdater.UpdateDeviceRespond(operateRespondVO, requestVO.ClientName)
		if err != nil {
			continue
		}
	}

}
